package com.hans.scala

import java.io.File

object FileMatcher {
  def main(args: Array[String]) {
    def filesEndWith(query: String) = filesMatching(query)(_.endsWith(_))
    def filesEqual(query: String) = filesMatching(query)(_.equals(_))
    def filesMatch(query: String) = filesMatching(query)(_.matches(_))
    //    val files = filesEnding(".scala")
    //    val fileList = files.toList
    //    println("file:" + fileList.mkString("\n"))
    println("\nfile:" + filesEndWith("Test.scala").mkString("\n"))
    println("\nfile:" + filesEqual("FileMatcher.scala").mkString("\n"))
    println("\nfile:" + filesMatch("Hello[a-zA-Z]+.scala").mkString("\n"))

  }

//  def filesEnding(query: String) = {
//    for {
//      file <- filesHere
//      if file.getName.endsWith(query)
//    } yield file
//  }
//
//  def filesContains(query: String) = {
//    for {
//      file <- filesHere
//      if file.getName.contains(query)
//    } yield file
//  }
//
//  def filesRegex(query: String) = {
//    for {
//      file <- filesHere
//      if file.getName.matches(query)
//    } yield file
//  }

  def filesMatching(query: String)(matches: (String, String) => Boolean): Array[File] = {
//    println(filesHere.mkString(","))
    for (file <- filesHere; if matches(file.getName, query)) yield file
//    for (
//      file <- filesHere
//      if matches(file.getName, query)
//    ) yield {
//      file
//    }
  }

  def filesHere = new File("src\\main\\scala\\com\\hans\\scala\\").listFiles()

}